﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using FastReflectionLib;
using SZHL.UI.AppCode;
using System.Data;
using SZHL.Data;

namespace SZHL.UI.API
{
    public class XXZXManage : IWsService
    {
        public void ProcessRequest(HttpContext context, ref Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            MethodInfo methodInfo = typeof(XXZXManage).GetMethod(msg.Action.ToUpper());
            XXZXManage model = new XXZXManage();
            methodInfo.FastInvoke(model, new object[] { context, msg, P1, P2, UserInfo });
        }
        /// <summary>
        /// 获取用户消息列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1">消息类型</param>
        /// <param name="P2">消息内容模糊查询</param>
        /// <param name="strUserName"></param>
        public void GETXXZXIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strWhere = "";
            if (P1 != "")
            {
                strWhere = string.Format(" and isRead='{0}' ", P1);
            }
            if (P2 != "")
            {
                strWhere += string.Format(" and MsgContent like  '%{0}%'", P2);

            }
            string strSQL = string.Format(@"SELECT MsgType,MsgContent,CRDate,UserFrom,isRead,ID from JH_Auth_User_Center Where UserTO='{0}'  {1}", UserInfo.User.UserName, strWhere);
            DataTable dt = new ZH_XTGGB().GetDTByCommand(strSQL);
            msg.Result = dt;

        }
        /// <summary>
        /// 删除消息
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1">消息ID</param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void DELXXZXBYID(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            try
            {

                if (new JH_Auth_User_CenterB().Delete(d => d.ID.ToString() == P1))
                {

                    msg.ErrorMsg = "";
                }
            }
            catch (Exception ex)
            {
                msg.ErrorMsg = ex.Message;
            }
        }
        /// <summary>
        /// 获取消息实体
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1">消息ID</param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETXXZXMODEL(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            msg.Result = new JH_Auth_User_CenterB().GetEntity(d => d.ID.ToString() == P1);
        }
        /// <summary>
        /// 更新读取状态
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void UPDTEREADSTATES(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            try
            {
                string strSql = "";
                if (P2 == "")
                {
                    string status = context.Request["s"] ?? "Y";
                    strSql = string.Format("UPDATE JH_Auth_User_Center set isRead='{0}' where ID={1} ",status, P1);
                }
                else if (P2 == "ALL")
                {
                    strSql = string.Format("UPDATE JH_Auth_User_Center set isRead='Y' where  UserTO='{0}' and isRead!='Y'", UserInfo.User.UserName);
                }
                new JH_Auth_User_CenterB().ExsSql(strSql);
            }
            catch (Exception ex)
            {
                msg.ErrorMsg = ex.Message;
            }
        }
        /// <summary>
        /// 获取首页的公司名称及消息数量
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="strParamData"></param>
        /// <param name="strUserName"></param>
        public void GETRCTXCOUNTANDCOMPANY(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strSql = string.Format("SELECT count(0) from JH_Auth_User_Center Where UserTO='{0}'And isRead='N' ", UserInfo.User.UserName);
            msg.Result = new ZH_RCTXB().ExsSclarSql(strSql);
            msg.Result1 = new JH_Auth_QYB().GetEntities().SingleOrDefault().QYName;
        }
    }
}